﻿myApp.controller("HomeController", function ($scope, $http, $modal, modalService, $sce, ngTableParams, $filter) {
    $scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 News', 'description': 'First hand property news. Updated instantly.' });
    $scope.thisPage = {};

    
    function pageInit() {
        //document.title = "Penang Realty 世界地產 EVENTS";
        //$scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 EVENTS', 'description': 'Join our event to obtain first hand info.' });
        $scope.loader = { loading: true };
        var url = 'api/Events/GetEvents';
        $http.get(url).success(function (data) {
            $scope.data.Events = data;
            console.log(data);
/*
            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 5,           // count per page
                filter: {
                    Name: ''       // initial filter
                }

            }, {
                total: $scope.data.Events.length, // length of data
                getData: function ($defer, params) {

                    var orderedEvents = params.filter() ? $filter('filter')($scope.data.Events, params.filter()) : $scope.data.Events;
                    // use build-in angular filter
                    orderedEvents = params.sorting() ?  $filter('orderBy')(orderedEvents, params.orderBy()) : orderedEvents;
                    params.total(orderedEvents.length); // set total for recalc pagination
                    $defer.resolve(orderedEvents.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                    $scope.loader = { loading: false };
                }
            })

*/
        })

    }
    

    function pageInit2() {
        $scope.thisPage.loading = true;
        var url = 'api/News/GetNews';
        $http.get(url).success(function (data) {
            $scope.thisPage.loading = false;
            $scope.data.News = data;
            console.log(data);

            /*
            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 25,           // count per page
                filter: {
                    Title: ''       // initial filter
                }

            }, {
                total: $scope.data.News.length, // length of data
                getData: function ($defer, params) {

                    var orderedNews = params.filter() ? $filter('filter')($scope.data.News, params.filter()) : $scope.data.News;
                    // use build-in angular filter
                    orderedNews = params.sorting() ?
                            $filter('orderBy')(orderedNews, params.orderBy()) : orderedNews;

                    params.total(orderedNews.length); // set total for recalc pagination
                    $defer.resolve(orderedNews.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                    $scope.loader = { loading: false };
                }
            })
            
            */
        })

    }


    pageInit();
    pageInit2();



})